﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.cn
{
    public partial class category : System.Web.UI.UserControl
    {
        // Fields
        public string typemsg = "";
        readonly BasePage theBasePage = new BasePage();

        private string sBigType
        {
            get
            {
                return Request.QueryString["sid"];
            }
        }

        // Methods
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                string sql = string.Empty;;
                string sType = string.Empty;;


                //if (theBasePage.UserCardCode != null)
                //{
                //    sType = " and proisnew2 = 1 and ProfessionAreaTypeID = (select ct.ProfessionAreaTypeID from DB_Card c join tbCardType ct on c.cardTypeid = ct.id where c.cardcode=" + theBasePage.UserCardCode + ")";
                //}

                 if (sBigType == "2")
                {
                    sType = " and proisnew2 = 1";
                }
                
                else if(sBigType == "3")
                {
                    sType = " and proisnew3 = 1";
                }
                else if (sBigType == "4")
                {
                    sType = " and proisnew4 = 1";
                }
                 //else if (sBigType == "2" && theBasePage.UserCardCode == null)
                 //{
                 //    return;
                 //}
                 else
                     {
                         sType = " and (proisnew3 = 1 or proisnew4 =1) ";
                     }
                sql = "select distinct classid,classname,parentid,classorder from DB_Productclass where  visible=1 and parentid = 0  "
                    + " and classid in (select PC.parentid from DB_Productclass PC join DB_Shoppro S on PC.classid = S.typeid and PC.parentid !=0 and PC.visible=1 " + sType +")"
                    + " and  parentid=0 and visible=1 order by classorder";
         
                DataTable table = SQLAccess.GreatDs(sql).Tables[0];
                if (table.Rows.Count > 0)
                {
                 
                    foreach (DataRow row in table.Rows)
                    {
                        string typemsg = this.typemsg;
                      //  this.typemsg = typemsg + "<h1><a href='products_category.aspx?typeid=" + row["classid"].ToString() + "'><font color='#e1e1e1'>" + row["classname"].ToString() + "</font></a></h1>";
                        this.typemsg = typemsg + "<h1><font>" + row["classname"].ToString() + "</font></h1>";
                        DataTable table2 = SQLAccess.GreatDs("select distinct PC.classid,PC.classname,PC.parentid,PC.classorder from DB_Productclass PC join DB_Shoppro S on PC.classid=S.typeid " + sType + " where PC.parentid=" + row["classid"].ToString() + " and PC.visible=1 order by PC.classorder").Tables[0];
                        if (table2.Rows.Count > 0)
                        {
                           
                            this.typemsg = this.typemsg + "<table border='0' cellpadding='0' cellspacing='0'><tr>";
                            //int num = 0;
                            foreach (DataRow row2 in table2.Rows)
                            {
                                string str4 = this.typemsg;
                                if (Request.QueryString["sid"] == "2")
                                {
                                    this.typemsg = str4 + "<td width='50%'><a href='professionArea.aspx?sid=" + Request.QueryString["sid"] + "&typeid=" + row2["classid"].ToString() + "'>" + row2["classname"].ToString() + "</a></td>";
                                }
                                else
                                {
                                    this.typemsg = str4 + "<td width='50%'><a href='hotpro.aspx?sid=" + Request.QueryString["sid"] + "&typeid=" + row2["classid"].ToString() + "'>" + row2["classname"].ToString() + "</a></td>";
                                }
                                //num++;
                                //if ((num % 2) == 0)
                                //{
                                    this.typemsg = this.typemsg + "</tr><tr>";
                               // }
                            }
                            this.typemsg = this.typemsg + "</tr></table>";
                        }
                    }
                }
            }
        }



    }
}